package com.qk.management.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.common.PageResult;
import com.qk.entity.Course;
import com.qk.management.mapper.CourseMapper;
import com.qk.management.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {
    @Autowired
    private CourseMapper courseMapper;

    @Override
    public PageResult<Course> page(Integer page, Integer pageSize, String name, Integer subject, Integer target) {
        PageHelper.startPage(page,pageSize);
        List<Course> list= courseMapper.list(name,subject,target);
        Page<Course> rs = (Page<Course>) list;
        return PageResult.<Course>builder()
                .total(Long.valueOf(rs.getTotal()).intValue())
                .rows(rs.getResult())
                .build();
    }

    @Override
    public void deleteById(Integer id) {
        courseMapper.deleteById(id);
    }

    @Override
    public void addCourse(Course course) {
        courseMapper.insert(course);
    }

    @Override
    public Course getById(Integer courseId) {
        return courseMapper.getById(courseId);
    }

    @Override
    public void update(Course course) {
        courseMapper.update(course);
    }

    @Override
    public List<Course> findAll() {
        return courseMapper.findAll();
    }

    @Override
    public List<Course> findBySubject(Integer subject) {
        return courseMapper.findBySubject(subject);
    }
}
